/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.com.remiseria.frame;

import ar.com.remiseria.bo.ChoferBO;
import ar.com.remiseria.bo.LicenciaBO;
import ar.com.remiseria.bo.TipoDeDocumentoBO;
import ar.com.remiseria.entities.Chofer;
import ar.com.remiseria.entities.Documento;
import ar.com.remiseria.entities.Domicilio;
import ar.com.remiseria.entities.Licencia;
import ar.com.remiseria.entities.TipoDeDocumento;
import ar.com.remiseria.utils.PropertiesReader;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author mcvalls
 */
public class EditarChoferFrame extends javax.swing.JFrame {

    private List<TipoDeDocumento> tipoDeDocumentoList = new ArrayList<TipoDeDocumento>();
    private List<Licencia> licenciaList = new ArrayList<Licencia>();
    private Chofer choferActual;
    /**
     * Creates new form AltaChoferFrame
     */
    public EditarChoferFrame(Chofer chofer) {
        this.choferActual = chofer;
        initComponents();
        this.getTiposDeDocumento();
        this.getLicencias();
        this.getDatosChoferActual();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        apellidoTxt = new javax.swing.JTextField();
        nombreTxt = new javax.swing.JTextField();
        tipoDeDocumentoComboBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        numeroDocumentoTxt = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        licenciaComboBox = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        observacionesTxt = new javax.swing.JTextField();
        guardarChoferBtn = new javax.swing.JButton();
        volverBtn = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        pisoTxt = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        departamentoTxt = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        calleTxt = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        numeroTxt = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        telefonoTxt = new javax.swing.JTextField();
        provinciaTxt = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        localidadTxt = new javax.swing.JTextField();
        codigoPostalTxt = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        archivoMenuBtn = new javax.swing.JMenu();
        guardarChoferMenuBtn = new javax.swing.JMenuItem();
        volverMenuBtn = new javax.swing.JMenuItem();
        ayudaMenuBtn = new javax.swing.JMenu();
        acercaDeMenuBtn = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Apellido*");

        jLabel2.setText("Nombre*");

        jLabel3.setText("Tipo de documento");

        jLabel4.setText("Numero Documento*");

        jLabel5.setText("Licencia*");

        jLabel14.setText("Observaciones");

        guardarChoferBtn.setText("Guardar chofer");
        guardarChoferBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarChoferBtnActionPerformed(evt);
            }
        });

        volverBtn.setText("Volver");
        volverBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                volverBtnActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
        jLabel15.setText("Los campos con * son obligatorios");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Domicilio"));

        jLabel9.setText("Piso");

        jLabel10.setText("Departamento");

        jLabel7.setText("Calle*");

        jLabel8.setText("Numero");

        jLabel6.setText("Telefono*");

        jLabel13.setText("Provincia*");

        jLabel12.setText("Localidad*");

        jLabel11.setText("C.P.");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9)
                    .addComponent(jLabel12)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(telefonoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(localidadTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(provinciaTxt))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(pisoTxt)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(departamentoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(calleTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(codigoPostalTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(numeroTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(0, 43, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(calleTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(numeroTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(pisoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(departamentoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(codigoPostalTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(localidadTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(provinciaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(telefonoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        archivoMenuBtn.setText("Archivo");

        guardarChoferMenuBtn.setText("Guardar chofer");
        guardarChoferMenuBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarChoferMenuBtnActionPerformed(evt);
            }
        });
        archivoMenuBtn.add(guardarChoferMenuBtn);

        volverMenuBtn.setText("Volver");
        volverMenuBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                volverMenuBtnActionPerformed(evt);
            }
        });
        archivoMenuBtn.add(volverMenuBtn);

        jMenuBar1.add(archivoMenuBtn);

        ayudaMenuBtn.setText("Ayuda");

        acercaDeMenuBtn.setText("Acerca de esta ventana");
        acercaDeMenuBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acercaDeMenuBtnActionPerformed(evt);
            }
        });
        ayudaMenuBtn.add(acercaDeMenuBtn);

        jMenuBar1.add(ayudaMenuBtn);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(observacionesTxt))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(guardarChoferBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(volverBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(licenciaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(apellidoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(22, 22, 22)
                                    .addComponent(jLabel2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(nombreTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tipoDeDocumentoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(numeroDocumentoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(apellidoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(nombreTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(numeroDocumentoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tipoDeDocumentoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(licenciaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(observacionesTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(guardarChoferBtn)
                    .addComponent(volverBtn)
                    .addComponent(jLabel15))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void guardarChoferBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarChoferBtnActionPerformed
        String mensaje = this.validarCampos(); // Valido que los campos obligatorios no esten vacios
        if(mensaje.equals("ok")){
            this.guardarChofer();
        }else{
            JOptionPane.showMessageDialog(this, mensaje);
        }        
    }//GEN-LAST:event_guardarChoferBtnActionPerformed

    private void volverBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_volverBtnActionPerformed
        ABMChoferesFrame acf = new ABMChoferesFrame();
        acf.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_volverBtnActionPerformed

    private void guardarChoferMenuBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarChoferMenuBtnActionPerformed
        guardarChoferBtnActionPerformed(evt);
    }//GEN-LAST:event_guardarChoferMenuBtnActionPerformed

    private void volverMenuBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_volverMenuBtnActionPerformed
        volverBtnActionPerformed(evt);
    }//GEN-LAST:event_volverMenuBtnActionPerformed

    private void acercaDeMenuBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acercaDeMenuBtnActionPerformed
        this.mostrarInfoVentana();
    }//GEN-LAST:event_acercaDeMenuBtnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditarChoferFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditarChoferFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditarChoferFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditarChoferFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditarChoferFrame(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem acercaDeMenuBtn;
    private javax.swing.JTextField apellidoTxt;
    private javax.swing.JMenu archivoMenuBtn;
    private javax.swing.JMenu ayudaMenuBtn;
    private javax.swing.JTextField calleTxt;
    private javax.swing.JTextField codigoPostalTxt;
    private javax.swing.JTextField departamentoTxt;
    private javax.swing.JButton guardarChoferBtn;
    private javax.swing.JMenuItem guardarChoferMenuBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox licenciaComboBox;
    private javax.swing.JTextField localidadTxt;
    private javax.swing.JTextField nombreTxt;
    private javax.swing.JTextField numeroDocumentoTxt;
    private javax.swing.JTextField numeroTxt;
    private javax.swing.JTextField observacionesTxt;
    private javax.swing.JTextField pisoTxt;
    private javax.swing.JTextField provinciaTxt;
    private javax.swing.JTextField telefonoTxt;
    private javax.swing.JComboBox tipoDeDocumentoComboBox;
    private javax.swing.JButton volverBtn;
    private javax.swing.JMenuItem volverMenuBtn;
    // End of variables declaration//GEN-END:variables

    private String validarCampos() {
        if(apellidoTxt.getText() == null || apellidoTxt.getText().length() == 0){
            return "El campo APELLIDO es obligatorio";
        }
        if(nombreTxt.getText() == null || apellidoTxt.getText().length() == 0){
            return "El campo NOMBRE es obligatorio";
        }
        if(numeroDocumentoTxt.getText() == null || numeroDocumentoTxt.getText().length() == 0){
            return "El campo NUMERO DE DOCUMENTO es obligatorio";
        }
        if(calleTxt.getText() == null || calleTxt.getText().length() == 0){
            return "El campo CALLE es obligatorio";
        }
        if(localidadTxt.getText() == null || localidadTxt.getText().length() == 0){
            return "El campo LOCALIDAD es obligatorio";
        }
        if(provinciaTxt.getText() == null || provinciaTxt.getText().length() == 0){
            return "El campo PROVINCIA es obligatorio";
        }
        if(telefonoTxt.getText() == null || telefonoTxt.getText().length() == 0){
            return "El campo TELEFONO es obligatorio";
        }
        return "ok";
    }

    private void guardarChofer() {
        /*
        Armo el objeto Chofer a partir de los campos de texto.
        */
        
        // Nombre y apellido
        choferActual.setApellido(apellidoTxt.getText());
        choferActual.setNombre(nombreTxt.getText());
        
        // Documento
        Documento documento = new Documento();        
        int seleccionado = tipoDeDocumentoComboBox.getSelectedIndex(); // Obtengo la posicion del tipo de doc seleccionado
        documento.setTipoDeDocumento(tipoDeDocumentoList.get(seleccionado)); // Obtengo el tipo de documento y se lo asigno a mi Documento
        documento.setNumero(Long.valueOf(numeroDocumentoTxt.getText()));
        
        choferActual.setDocumento(documento); // Asigno el documento al chofer.
        
        // Licencia
        seleccionado = licenciaComboBox.getSelectedIndex(); // Obtengo la posicion de la licencia seleccionada
        choferActual.setLicencia(licenciaList.get(seleccionado)); // Asigno la licencia al chofer
        
        // Domicilio        
        Domicilio domicilio = new Domicilio();
        
        if(calleTxt.getText() != null && calleTxt.getText().length() > 0){
            domicilio.setCalle(calleTxt.getText());
        }
        if(numeroTxt.getText() != null && numeroTxt.getText().length() > 0){
            domicilio.setNumero(Integer.valueOf(numeroTxt.getText()));
        }
        if(pisoTxt.getText() != null && pisoTxt.getText().length() > 0){
            domicilio.setPiso(Integer.valueOf(pisoTxt.getText()));
        }
        if(departamentoTxt.getText() != null && departamentoTxt.getText().length() > 0){
            domicilio.setDepartamento(departamentoTxt.getText());
        }
        if(codigoPostalTxt.getText() != null && codigoPostalTxt.getText().length() > 0){
            domicilio.setCodigoPostal(Integer.valueOf(codigoPostalTxt.getText()));
        }
        if(localidadTxt.getText() != null && localidadTxt.getText().length() > 0){
            domicilio.setLocalidad(localidadTxt.getText());
        }
        if(provinciaTxt.getText() != null && provinciaTxt.getText().length() > 0){
            domicilio.setProvincia(provinciaTxt.getText());
        }
        
        choferActual.setDomicilio(domicilio);
        
        // Telefono
        choferActual.setTelefono(telefonoTxt.getText());
        
        // Observaciones
        if(observacionesTxt.getText() != null && observacionesTxt.getText().length() > 0){
            choferActual.setObservaciones(observacionesTxt.getText());
        }
        
        ChoferBO choferBO = new ChoferBO();
        try{
            choferBO.updateChofer(choferActual);
            JOptionPane.showMessageDialog(this, "Guardado exitosamente.");
            guardarChoferBtn.setEnabled(false);
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex);
            ex.printStackTrace();
        }
    }
    

    private void getTiposDeDocumento() {
        List<TipoDeDocumento> tiposDocumentos = new ArrayList<TipoDeDocumento>();
        TipoDeDocumentoBO tipoDeDocBO = new TipoDeDocumentoBO();
        try{
            tiposDocumentos = tipoDeDocBO.getAllTipoDeDocumento();
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex);
        }
        if(tiposDocumentos != null && !tiposDocumentos.isEmpty()){
            for(TipoDeDocumento tdd : tiposDocumentos){
                tipoDeDocumentoComboBox.addItem(tdd.getDescripcion());
                tipoDeDocumentoList.add(tdd);
            }
        }
    }

    private void getLicencias() {
        List<Licencia> licencias = new ArrayList<Licencia>();
        LicenciaBO licenciaBO = new LicenciaBO();
        try{
            licencias = licenciaBO.getAllLicencias();
            
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex);
            ex.printStackTrace();
        }
        if(licencias != null && !licencias.isEmpty()){
            for(Licencia lic : licencias){
                licenciaComboBox.addItem(lic.getTipoLicencia()+" - "+lic.getDescripcion());
                licenciaList.add(lic);
            }
        }
    }

    private void mostrarInfoVentana() {
        String mensaje = PropertiesReader.getInstance().getApplicationMessage("ayuda.acerca.altaChofer");
        JOptionPane.showMessageDialog(this, mensaje);
    }
    
      private void getDatosChoferActual() {
        /*
        Relleno los campos del jFrame con los datos del chofer a editar.
        */
        apellidoTxt.setText(this.choferActual.getApellido());
        nombreTxt.setText(this.choferActual.getNombre());
        
        short contador = 0;
        for(int i = 0; i<tipoDeDocumentoList.size(); i++){
            TipoDeDocumento tdd = (TipoDeDocumento)tipoDeDocumentoList.get(i);
//            if(tdd.equals(this.choferActual.getDocumento().getTipoDeDocumento())){
            if(tdd.getCodigo().equals(this.choferActual.getDocumento().getTipoDeDocumento().getCodigo())){
                break;
            }else{
                contador++;
            }
        }
        tipoDeDocumentoComboBox.setSelectedIndex(contador);
        
        if(this.choferActual.getDocumento().getNumero() != null){
            numeroDocumentoTxt.setText(this.choferActual.getDocumento().getNumero().toString());
        }
        
        contador = 0;
        for(int i = 0; i < licenciaList.size(); i++){
            Licencia lic = (Licencia) licenciaList.get(i);
            if(lic.getCodigo().equals(this.choferActual.getLicencia().getCodigo())){
                break;
            }else{
                contador++;
            }
        }
        licenciaComboBox.setSelectedIndex(contador);
        
        Domicilio dom = this.choferActual.getDomicilio();
        
        calleTxt.setText(dom.getCalle());
        if(dom.getNumero() != null){
            numeroTxt.setText(String.valueOf(dom.getNumero()));
        }        
        if(dom.getPiso() != null){
            pisoTxt.setText(String.valueOf(dom.getPiso()));
        }
        departamentoTxt.setText(dom.getDepartamento());
        if(dom.getCodigoPostal() != null){
            codigoPostalTxt.setText(String.valueOf(dom.getCodigoPostal()));
        }
        localidadTxt.setText(dom.getLocalidad());
        provinciaTxt.setText(dom.getProvincia());
        
        telefonoTxt.setText(this.choferActual.getTelefono());
        
        observacionesTxt.setText(this.choferActual.getObservaciones());
        
    }
}
